package com.s10.ecloud.web.model;

import java.sql.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany;

@MappedSuperclass
public class User {

	private Integer id;
	private String name;
	private String password;
	private String gender;
	private String personalId;
	private String email;
	private String address;
	private String zipcode;
	private String phone;
	private String mobile;
	private String qq;
	private String website;
	private District district;
	private Date loginDate;
	private Date updateDate;
	private Date registDate;

	private boolean online;

	/**
	 * state: 0 waiting to activate 1.activated & waiting audit, 2 valid 3
	 * invalid
	 * 
	 * For Individual client, state will be set to 2 after activating register
	 * For Enterprise client, state will be set to 1 after activating register
	 * to wait audit, state will be 2 after audit For System user, state will be
	 * set to 2 after it being created.
	 */
	private int state;
	private Role role;
	private Set<Log> logs = new HashSet<Log>(0);

	// Constructors

	/** default constructor */
	public User() {
	}

	/** full constructor */
	public User(String username, String password, int state, Role role,
			Set<Log> logs) {
		this.name = username;
		this.password = password;
		this.state = state;
		this.role = role;
		this.logs = logs;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "ID")
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "NAME", nullable = false, length = 30)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "PASSWORD", nullable = false, length = 100)
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name = "GENDER", nullable = false, length = 30)
	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	@Column(name = "PERSONALID", nullable = false, length = 100)
	public String getPersonalId() {
		return personalId;
	}

	public void setPersonalId(String personalid) {
		this.personalId = personalid;
	}

	@Column(name = "EMAIL", nullable = false, length = 30)
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Column(name = "ADDRESS", nullable = false, length = 80)
	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	@Column(name = "ZIPCODE", nullable = false, length = 10)
	public String getZipcode() {
		return zipcode;
	}

	public void setZipcode(String zipcode) {
		this.zipcode = zipcode;
	}

	@Column(name = "PHONE", nullable = false, length = 20)
	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	@Column(name = "MOBILE", nullable = false, length = 20)
	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	@Column(name = "DISTRICT")
	public District getDistrict() {
		return district;
	}

	public void setDistrict(District district) {
		this.district = district;
	}

	@Column(name = "QQ", nullable = false, length = 20)
	public String getQq() {
		return qq;
	}

	public void setQq(String qq) {
		this.qq = qq;
	}

	@Column(name = "WEBSITE", nullable = false, length = 30)
	public String getWebsite() {
		return website;
	}

	public void setWebsite(String website) {
		this.website = website;
	}

	@Column(name = "LOGIN_DATE")
	public Date getLoginDate() {
		return loginDate;
	}

	public void setLoginDate(Date loginDate) {
		this.loginDate = loginDate;
	}

	@Column(name = "UPDATE_DATE")
	public Date getUpdateDate() {
		return updateDate;
	}

	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}

	@Column(name = "REGISTER_DATE")
	public Date getRegistDate() {
		return registDate;
	}

	public void setRegistDate(Date registDate) {
		this.registDate = registDate;
	}

	@Column(name = "ONLINE")
	public boolean isOnline() {
		return online;
	}

	public void setOnline(boolean online) {
		this.online = online;
	}

	@Column(name = "STATE")
	public int getState() {
		return state;
	}

	public void setState(int state) {
		this.state = state;
	}

	// 这里指自身与别的表做外键 所以是ManyToOne
	@ManyToOne(fetch = FetchType.LAZY)
	// 设置自身哪个属性与别的表的主键做外键
	@JoinColumn(name = "roleId")
	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "user")
	public Set<Log> getLogs() {
		return logs;
	}

	public void setLogs(Set<Log> logs) {
		this.logs = logs;
	}

}
